package wang.chunfan.springcloud.learning.stream.rabbitmq.partition;

import org.springframework.cloud.stream.binder.PartitionKeyExtractorStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component
public class MyPartitionKeyStrategy implements PartitionKeyExtractorStrategy {
    @Override
    public Object extractKey(Message<?> message) {
        Object object = message.getPayload();

        Random random = new Random();
        int index = random.nextInt(2);
        System.out.println(index);
        return index;
    }
}
